package com.xgxx.chendawei.system.utils.api;


import com.xgxx.chendawei.enums.ApiResponseEnum;

/**
 * web层统一返回工具类
 */
public class ApiResponseUtil {
    /**
     * 获取请求成功响应的ApiResponse
     *
     * @param data
     * @return
     */
    public static ApiResponse getApiResponse(Object data) {
        return getApiResponse(data, ApiResponseEnum.SUCCESS.getCode(), ApiResponseEnum.SUCCESS.getMsg());
    }

    /**
     * 获取其他请求响应的ApiResponse
     *
     * @param code
     * @param msg
     * @return
     */
    public static ApiResponse getApiResponse(int code, String msg) {
        return getApiResponse(null, code, msg);
    }

    public static ApiResponse getCommErrorApiResponse(String msg) {
        return getApiResponse(null, ApiResponseEnum.DEFAULT_ERROR.getCode(), msg);
    }

    /**
     * 枚举信息转统一返回对象
     *
     * @param apiResponseEnum
     * @return
     */
    public static ApiResponse getApiResponse(ApiResponseEnum apiResponseEnum) {
        return getApiResponse(apiResponseEnum.getCode(), apiResponseEnum.getMsg());
    }


    public static ApiResponse getApiResponse(Object data, int code, String msg) {
        ApiResponse apiResponse = new ApiResponse(data);
        apiResponse.setCode(code);
        apiResponse.setMsg(msg);
        return apiResponse;
    }

}
